#include "cmode.h"

static std::string translate(const std::string &cpy)
{
    std::string cpy2;
    for(auto c : cpy)
    {
        if(c == '\b')
        {
            cpy2 += "\\b";
        }
        else
        {
            cpy2.push_back(c);
        }
    }
    return cpy2;
}


int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("Usage: %s lig n\n", argv[0]);
        return -1;
    }
    CMode cpy;
    for(auto i = 1; i < argc; i++)
    {
        printf("Input:%s\n", argv[i]);
        if(std::string(argv[i]) == "C")
        {
            printf("Call Clear\n");
            cpy.Clear();
            continue;
        }
        if('E' == argv[i][0])
        {
            printf("Enable syll [%s]\n", argv[i]+1);
            cpy.Enable(argv[i]+1);
            continue;
        }
        if('D' == argv[i][0])
        {
            printf("Disable syll [%s]\n", argv[i]+1);
            cpy.Disable(argv[i]+1);
            continue;
        }
        if(cpy.Input(argv[i]))
        {
            printf("Correct pinyin:%s\n", translate(cpy.Correct()).c_str());
            printf("Corrected pinyin:%s\n", cpy.Corrected().c_str());
        }
        printf("Original pinyin:%s\n", cpy.Original().c_str());
    }
    return 0;
}

